package com.zhengxyou.kotlindemo.basic

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.zhengxyou.kotlindemo.R

/**
 *<h3>基础</h3>
 *
 * <p>kotlin数字没有隐式转换，如int不能隐式转换为long</p>
 * <p>字符不是数字</p>
 * <p>默认的浮点数为Double类型</p>
 */
class BasicActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_basic)

        implicitConversion()

        //默认浮点为dobule
        val mDobule = 2.0
        //float
        val mFloat = 2.0F
//        val mD: Double = 2

        //数字字值可以用下划线
        val oneMillion = 1_000_000
        val creditCardNumber = 1234_5678_9012_3456L
        val socialSecurityNumber = 999_99_9999L
        val hexBytes = 0xFF_EC_DE_5E
        val bytes = 0b11010010_01101001_10010100_10010010

        // 创建一个 Array<String> 初始化为 ["0", "1", "4", "9", "16"]
        val asc = Array(5) { i -> (i * i).toString() }
        asc.forEach { println(it) }
    }

    /**
     * 隐式转换测试
     */
    private fun implicitConversion() {
        val mNum = 1
        var mDobule = 1L
//        mDobule = mNum
    }
}
